<%@ include file="/en/jsp/static.jsp" %>
<%@ taglib uri="/linuxbox/UserAdmin.tld" prefix="user" %>
<%@ page import="linuxbox.admin.logic.*" %>
<jsp:include page="/en/jsp/header.jsp" flush="true"/>
<%
  UserGrpObject ugo = (UserGrpObject)request.getAttribute("USER_GRP");

  String GROUP_ID = Integer.toString(ugo.getID());
  String GROUP_NAME = ugo.getName();
  String DESC = ugo.getDesc();
%>
<SCRIPT LANGUAGE="Javascript">
function checkFields() {
  if (document.confirm.GROUP_NAME.value == null
  || document.confirm.GROUP_NAME.value == "") {
    alert("The group name is missing.");
    return false;
  }

  return true;
}

function saveChanges() {
  if (checkFields()) {
      var options = document.confirm.listMember.options;
      if ( options.length > 0) {
            for (i = options.length - 1; i >= 0; i--) {
          options[i].selected = true;
        }
        }
      document.confirm.action = "<%=BoxStatic.servletDir%>UserGrpUpdateAction";
      document.confirm.submit();
  }
}

function moveDualList(srcList, destList, moveAll) {
  // Do nothing if nothing is selected
  if ((srcList.selectedIndex == -1) && (moveAll == false)) {
    return;
  }

  newDestList = new Array(destList.options.length);
  var len = 0;
  for (len = 0; len < destList.options.length; len++ ) {
    if (destList.options[len] != null) {
      newDestList[len] = new Option(destList.options[len].text,
        destList.options[len].value);
    }
  }

  for (var i = 0; i < srcList.options.length; i++ ) {
    if (srcList.options[i] != null &&
    (srcList.options[i].selected == true || moveAll)) {
       // Statements to perform if option is selected
       // Incorporate into new list
       newDestList[len] = new Option(srcList.options[i].text,
         srcList.options[i].value);
       len++;
    }
  }

  // Sort out the new destination list
  //newDestList.sort(compareOptionValues);   // BY VALUES
  //newDestList.sort(compareOptionText);   // BY TEXT

  // Populate the destination with the items from the new array
  for (var j = 0; j < newDestList.length; j++) {
    if (newDestList[j] != null ) {
      destList.options[j] = newDestList[j];
    }
  }

  // Erase source list selected elements
  for(var i = srcList.options.length - 1; i >= 0; i--) {
    if (srcList.options[i] != null &&
    (srcList.options[i].selected == true || moveAll)) {
       // Erase Source
       //srcList.options[i].value = "";
       //srcList.options[i].text  = "";
       srcList.options[i]       = null;
    }
  }
} // End of moveDualList()
</SCRIPT>

<table width="100%" height=26 align=middle border=0 cellpadding=0 cellspacing=0 bgcolor="#f4f4f4" style="font-size:16px;color:#d05000">
<tr><td>
    &nbsp;<img src="<%=BoxStatic.imageDir%>itemball.jpg" width=14 height=15 border=0 align="absmiddle">
    <b><%=boxName%> - User Group Management</b>
</td></tr>
</table>
<br>

<FORM METHOD="POST" NAME="confirm">
<INPUT TYPE="hidden" NAME="GROUP_ID" VALUE="<%=GROUP_ID%>">
<DIV>
<TABLE ALIGN="center" BGCOLOR="#336633" BORDER="0" CELLPADDING="1" CELLSPACING="0" WIDTH="98%">
  <TR><TD class="bg_darkgreen">
  <TABLE ALIGN="center" BGCOLOR="#336633" BORDER="0" CELLPADDING="0" CELLSPACING="5" WIDTH="100%">
  <TR><TD class="bg_darkgreen">
    <p class="white"><b>&nbsp;Edit User Group Profile</b></p>
  </TD></TR>
  </TABLE>

    <TABLE ALIGN="center" BGCOLOR="#f6f6f6" BORDER="0" CELLPADDING="5" CELLSPACING="0" WIDTH="100%" HEIGHT="100%">
  <TR><TD class="bg_lightgray" colspan="2"><br>
    <p class="red">&nbsp;&nbsp; <i>Note: Required fields are indicated with an Asterisk (*).</i></p>
  </TD></TR>
    <TR>
      <TD ALIGN="left" VALIGN="top" WIDTH="30%" class="bg_lightgray">
      <DIV><B>User Group Name</B></DIV>
      </TD>
      <TD ALIGN="left" VALIGN="top" WIDTH="70%" class="bg_lightgray">
      <DIV><INPUT TYPE="text" SIZE="64" NAME="GROUP_NAME" MAXLENGTH="64" VALUE="<%=GROUP_NAME%>"></DIV>
      </TD>
    </TR>
    <TR>
      <TD ALIGN="left" VALIGN="top" class="bg_lightgray">
      <DIV><B>Description</B></DIV>
      </TD>
      <TD ALIGN="left" VALIGN="top" class="bg_lightgray">
      <DIV><INPUT TYPE="text" SIZE="64" NAME="DESC" MAXLENGTH="128" VALUE="<%=DESC%>"></DIV>
      </TD>
    </TR>
    <TR>
      <TD ALIGN="left" VALIGN="top" class="bg_lightgray">
      <DIV><B>Group members</B></DIV>
      </TD>
      <TD ALIGN="left" VALIGN="top" class="bg_lightgray">
      <DIV><B>Not group members</B></DIV>
      </TD>
    </TR>
    <TR>
      <TD colspan="2" ALIGN="left" VALIGN="top" class="bg_lightgray">
      <DIV>
        <table>
        <tr><td>
        <select name="listMember" multiple size="10" style="width:70">
          <user:GroupMemberList groupID="<%=GROUP_ID%>" listType="select" memberType="in"/>
        </select></td>

        <td><input type="button" name="Add" value="Add <<"
        onclick="moveDualList(document.confirm.listNoMember,
        document.confirm.listMember, false)">
        <BR>
        <input type="button" name="Remove" value="Remove >>"
        onclick="moveDualList(document.confirm.listMember,
        document.confirm.listNoMember, false)">
        <BR>
        <input type="button" name="Add All" value="Add All <<"
        onclick="moveDualList(document.confirm.listNoMember,
        document.confirm.listMember, true)">
        <BR>
        <input type="button" name="Remove All"  value="Romve All >>"
        onclick="moveDualList(document.confirm.listMember,
        document.confirm.listNoMember, true)"></td>

        <td><select name="listNoMember" multiple size="10" style="width:70">
          <user:GroupMemberList groupID="<%=GROUP_ID%>" listType="select" memberType="out"/>
        </select></td></tr>
        </table>
      </DIV>
      </TD>
    </TR>
    <TR><TD class="bg_lightgray" colspan="2">
    <HR NOSHADE size="1">
     <DIV>
      <A HREF="javascript: saveChanges()"><IMG src="<%=BoxStatic.imageDir%>hbeam_btn_save.gif" width="110" height="20" border="0" alt="Save Changes"></A><!--
      --><A HREF="<%=BoxStatic.jspDir%>admin/UserGrpAdmin.jsp"><IMG SRC="<%=BoxStatic.imageDir%>hbeam_btn_cancel.gif" width="110" height="20" border="0" alt="Cancel"></A><BR>
     </DIV>
     </TD></TR>
  </TABLE>
</TD></TR>
</TABLE>
</DIV>
</FORM>
<jsp:include page="/en/jsp/footer.jsp" flush="true"/>
